package net.ycxinxing.mcpebox.ui;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.design.widget.TextInputEditText;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.LinearLayout;
import android.widget.Spinner;
import android.widget.TextView;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import net.ycxinxing.mcpebox.NativeAPI;
import net.ycxinxing.mcpebox.Pro.R;
import net.ycxinxing.mcpebox.baseActivity;
import net.ycxinxing.mcpebox.mDialog;
import cn.bmob.v3.Bmob;
import cn.bmob.v3.BmobUser;
import net.ycxinxing.mcpebox.bean.mUser;

public class MainActivity extends baseActivity
{
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		// TODO: Implement this method
		super.onCreate(savedInstanceState);
        //NativeAPI.hook();
		if (getSharedPreferences("data", MODE_PRIVATE).getBoolean("safemode", false))
		{
			mDialog dlg=new mDialog(this){
				@Override
				public void onButtonClick(int i)
				{
					if (i == 1)
					{
						getSharedPreferences("data", MODE_PRIVATE).edit().putBoolean("safemode", false).commit();
						Intent intent = getBaseContext().getPackageManager()  
							.getLaunchIntentForPackage(getBaseContext().getPackageName());  
						intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);  
						startActivity(intent); 
					}
					// TODO: Implement this method
				}
			};
			dlg.setButton2("退出安全模式");
			dlg.setButton3("继续");
			dlg.setTitle("安全模式");
			TextView tv=new TextView(this);
			tv.setText("因为某种原因，你已经开启安全模式。\n这个模式中，您无法加载插件\n这个模式仅仅是用来测试应用，正常使用请关闭。");
			dlg.setView(tv);
			dlg.show();
		}
		new File("/data/data/" + getPackageName() + "/jnitmp/").mkdirs();
		new File("/data/data/" + getPackageName()+"/addons/").mkdirs();
		new File("/sdcard/ycxinxing/mcpebox/var/").mkdirs();
		setContentView(R.layout.view_fabactivity);
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu)
	{
		menu.add("启动游戏");
		menu.add("版本安装器");
		menu.add("addon管理器");
		menu.add("材质包管理器");
		menu.add("插件(需重启)");
		menu.add("账户");
		menu.add("设置");
		menu.addSubMenu("更多...");
		// TODO: Implement this method
		return super.onCreateOptionsMenu(menu);
	}
	@Override
	public boolean onOptionsItemSelected(MenuItem item)
	{
		switch (item.getTitle().toString())
		{
			case "启动游戏":
				startActivity(new Intent(this,prepareLaunch.class));
				break;
			case "版本安装器":
				startActivity(new Intent(this,InstallActivity.class));
				break;
			case "addon管理器":
				startActivity(new Intent(this,AddonMgr.class));
				break;
			case "材质包管理器":
				startActivity(new Intent(this,TextureManager.class));
				break;
			case "账户":
				if(BmobUser.getCurrentUser(mUser.class)==null)
				{
					startActivity(new Intent(this,LoginActivity.class));
				}else{
					startActivity(new Intent(this,AccountActivity.class));
				}
				break;
			case "设置":
				startActivity(new Intent(this,SettingActivity.class));
				break;
		}
		// TODO: Implement this method
		return super.onOptionsItemSelected(item);
	}


}
